#### FOR FIGURE S11 IN THE SUPPLEMENTARY MATERIAL:
rm(list=ls())
library(foreign)
library(ggplot2) 
library(gridExtra)
library(knitr)
library(grid)
library(dplyr)
library(forcats)
#install.packages("extrafont")
library(extrafont)
#install.packages("performance")
library("performance")
library("see")
library("haven")

######### Placebow/Starbucks -------

setwd("~/Dropbox/Side projects/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Data")
setwd("/Users/sergimartinez/Dropbox/EUI/BET HOUSES PROJECT/data/estimates_050121/")

toplot1 <- read_dta("gambling_data.dta")
toplot1<- na.omit(toplot1)
toplot1$pau <- as.numeric(toplot1$pau)
toplot1$renta2 <- ordered(toplot1$renta2,
                          levels = c(0,1),
                          labels = c("Schools in Neighborhoods below Median income", "Schools in Neighborhoods above Median income"))
toplot1$publico <- ordered(toplot1$publico,
                           levels = c(1,2),
                           labels = c("Charter High-schools", "Public High-schools"))


theme_results <- theme_bw(base_size = 12) +
  theme(text=element_text(family="Times",size = 12),
        axis.text.x = element_text(size = 12, color = "black"),
        axis.text.y = element_text(size = 12, color = "black"),
        axis.title.y = element_text(size = 12, color = "black"),
        axis.title.x = element_text(size = 12, color = "black"),
        legend.position = "bottom",
        legend.key = element_rect(fill = NA),
        legend.text = element_text(size = 12),
        legend.title = element_text(size = 12),
        strip.text.y.right = element_text(angle = 0),
        strip.background = element_rect(fill = "white"),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        legend.background=element_blank(),
        strip.text.x = element_text(size=10))
palette2 = c("black", "blue", "red")

figureS11 <- toplot1%>%
  ggplot(aes(x = logdist_year_star, y = pau, color=publico))+
  geom_smooth(method="lm", se=T)+
  geom_jitter(alpha=0.1)+
  scale_color_manual(name = "Type of High-Schools:",values = palette2)+
  theme_minimal()+
  xlab("Logged Distance to the Closest Starbucks")+
  ylim(c(4,8)) +
  guides(color=guide_legend(override.aes=list(fill=NA)))+
  ylab("Educational performance") +
  facet_wrap(.~renta2) +
  theme_results +
  theme(legend.position = "top")

figureS11
#??ggsave("plotdistance_starbucks2.png", plot=figureS11, width = 30, height = 20, units = "cm")
